package com.yao.mall.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yao.mall.common.Result;

import com.yao.mall.model.dto.BrandRequest;
import com.yao.mall.model.dto.BrandSearchRequest;
import com.yao.mall.model.vo.BrandVO;
import com.yao.mall.service.BrandService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author jiahua.yao
 * @version 1.0
 * @description 品牌控制类
 * @date 2024/3/11 20:51
 */
@RestController
@RequestMapping("/brand")
@Slf4j
@Tag(name = "品牌信息相关接口")
public class BrandController {

    @Resource
    private BrandService brandService;

    @PostMapping("/getBrand")
    @Operation(summary = "品牌查看")
    public Result<Page<BrandVO>> getBrand(@RequestBody BrandSearchRequest brandSearchRequest) {
        Page<BrandVO> brandVOList = brandService.getBrandList(brandSearchRequest);
        return Result.success(brandVOList);
    }

    @GetMapping("/get/{cateId}")
    @Operation(summary = "通过分类id获取品牌信息")
    public Result<List<BrandVO>> getBrandByCateId(@PathVariable Long cateId) {
        List<BrandVO> brandVO = brandService.getBrandByCateId(cateId);
        return Result.success(brandVO);
    }

    @PostMapping("/add")
    @Operation(summary = "添加品牌")
    public Result<Boolean> addBrand(@RequestBody BrandRequest brandRequest) {
        Boolean aBoolean = brandService.addBrand(brandRequest);
        return Result.success(aBoolean);
    }

    @PutMapping("/update")
    @Operation(summary = "修改品牌")
    public Result<Boolean> updateBasic(@RequestBody BrandRequest brandRequest) {
        Boolean aBoolean = brandService.updateBasic(brandRequest);
        return Result.success(aBoolean);
    }
    @DeleteMapping("/{id}")
    @Operation(summary = "删除品牌")
    public Result<Boolean> deleteBrand(@PathVariable Long id) {
        Boolean aBoolean = brandService.deleteBrand(id);
        return Result.success(aBoolean);
    }

}
